# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=lsp-server
pkgbase=mingw-w64-python-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_realname}
pkgver=1.3.3
pkgrel=2
pkgdesc='Python Language Server for the Language Server Protocol (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('MIT')
url='https://github.com/python-lsp/python-lsp-server'
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-autopep8
    ${MINGW_PACKAGE_PREFIX}-python-flake8
    ${MINGW_PACKAGE_PREFIX}-python-jedi
    ${MINGW_PACKAGE_PREFIX}-python-jsonrpc-server
    ${MINGW_PACKAGE_PREFIX}-python-lsp-jsonrpc
    ${MINGW_PACKAGE_PREFIX}-python-mccabe
    ${MINGW_PACKAGE_PREFIX}-python-pluggy
    ${MINGW_PACKAGE_PREFIX}-python-pycodestyle
    ${MINGW_PACKAGE_PREFIX}-python-pydocstyle
    ${MINGW_PACKAGE_PREFIX}-python-pyflakes
    ${MINGW_PACKAGE_PREFIX}-python-pylint
    ${MINGW_PACKAGE_PREFIX}-python-pytest
    ${MINGW_PACKAGE_PREFIX}-python-rope
    ${MINGW_PACKAGE_PREFIX}-python-ujson
    ${MINGW_PACKAGE_PREFIX}-python-yapf
)
makedepends=(${MINGW_PACKAGE_PREFIX}-python-setuptools)
source=(https://github.com/python-lsp/python-${_realname}/archive/v${pkgver}.tar.gz)
sha256sums=('c37b89b4ba3dda15c20e3845be2dfef947d62c26fb3f58a086570603b1896d2d')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "python-${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    # Remove shebang line
    sed -e '1 { s/^#!.*$// }' -i "${_f}"
  done

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
